
<!-- 跟单-发起人列表 -->
<template>
  <div class="all">
    
    <!--搜索栏-->
    <div class="search bg2">
      <div class="search-content bg1">
        <LImage class="search-image" :src="Config.img('sousuo.png')"></LImage>
        <input class="search-input font28 text1"
              :ref="'input'"
              :placeholder="T('输入发起人昵称')"
              v-model="text"
              type="text"
              @return="onReturn">

        <div class="search-but" @click="searchClick">
          <text class="font24 main-t1">{{T('搜索')}}</text>
        </div>
      </div>
    </div>
    
    <list class="list" :loadmoreoffset="250" @loadmore="httpMansLoading">
    
      <!--刷新-->
      <refresh class="refresh" @refresh="httpMans" :display="isRefresh ? 'show' : 'hide'">
        <loading-indicator class="load text1"></loading-indicator>
      </refresh>

      <!--内容-->
      <cell v-for="(item, index) in mans" v-bind:key="index">

        <div class="cell" v-if="item.nickName" @click="manClick(item)">

          <div class="cell-info bg2">

            <LImage class="cell-image bg3" :src="item.avatar ? item.avatar : Config.img('view_image_portrait_normal.png')"></LImage>
            
            <div class="column">
              <text class="font32 text1">{{item.nickName}}</text>
              <div class="row acenter">
                <div v-for="(item, index) in item.exchangeNames" v-bind:key="'10000'+index">
                  <div class="cell-exch bk1" v-if="index < 3">
                    <text class="font20 text1">{{item}}</text>
                  </div>
                </div>
              </div>

              <div class="height20"></div>
              <text class="cell-mark font24 text2">{{item.mark}}</text>
            </div>

            <div class="all"></div>
            <div class="column aend">
              <text :class="['font32', Config.upDownFont(item.realYearIncome)]">{{math.addJia(item.realYearIncome)+'%'}}</text>
              <div class="height20"></div>
                <text class="font24 text3">{{T('年化收益率')}}</text>
            </div>

            <LImage class="texture2" :src="Config.img('texture2.png')"></LImage>
          </div>

          <div class="cell-total bg3">
            <text class="font20 text3">{{T('累计跟单投入')+'/'+T('收益')}}</text>
            <div class="all"></div>
            <text class="font24 text3">{{item.totalInvest+'/'+item.totalIncome+' '+'BTC'}}</text>
          </div>
        </div>

        <div class="tipe" v-else>
          <text class="tipe-text font20 text3">{{T('跟单数据实时更新，历史表现不能代表未来收益；')}}</text>
          <text class="tipe-text font20 text3">{{T('年化收益率较低的数据将不会被展示在列表中；')}}</text>
          <text class="tipe-text font20 text3">{{T('市场有风险，投资需谨慎。')}}</text>
        </div>

      </cell>
    </list>
  </div>
</template>

<script>

import Config from "@/_js/config";
import navigator from "@/_js/navigator";
import modal from "@/_js/modal";
import math from "@/_js/math";

import weexHttp from "@/_js/https"; ;
const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T('搜索'));

export default {

  data() {
    return {
      Config:Config,
      T:T,
      math:math,
      PATH:"https://obs-vt.obs.ap-southeast-1.myhuaweicloud.com/res/weex/strategy/",
  
      mans:[{}], //发起人列表
      text:'',
      searchKey:'', //搜索关键字
      
      pageNo:0, //页码
      pageMax:false, //turn最大页面
      
      isRefresh:false, //显示刷新
      isLoadinging:false, //显示加载
    };
  },

  mounted() {
    Config.init(()=>{
    },[Config.OPT_UP_DOWN]);
  },


  methods: {
    /*************************************************其他*/
    //处理数据
    opData(data){
      for (let index = 0; index < data.length; index++) {
        var datas = data[index];
        datas['exchangeNames'] = datas.exchangeNames ? datas.exchangeNames : [];
      }
    },

    //处理Model
    opModel() {
      var model = {mans:this.mans, pageNo:this.pageNo, pageMax:this.pageMax};
      this.$emit("change", model);
    },

    /********************************** HTTP*/
    //发起人列表-刷新
    httpMans() {

      if (this.searchKey == '') {
        this.pageNo = 1;
        this.pageMax = true;
        this.mans = [{}];
        return;
      }

      if (this.isRefresh || this.isLoadinging) return;
      this.isRefresh = true;

      var param = {pageNo:1, "key":this.searchKey};
      weexHttp.post("follow/queryInitiatorList",param,true,(data) => {
          this.isRefresh = false;

          if (data.status == 200) {
            data = data.data;
            this.opData(data);

            this.mans = data;
            this.pageNo = 1;
            this.pageMax = data.length < 20;
            if(this.pageMax) {
              this.mans.push({});
              };
            this.opModel();
          } else {
            modal.toast(data.msg);
          }
        }
      );
    },

    //发起人列表-加载
    httpMansLoading() {

      if (this.pageMax || this.isRefresh || this.isLoadinging) return;
      this.isLoadinging = true;

      var param = {pageNo:this.pageNo+1, "key":this.searchKey};
      weexHttp.post("follow/queryInitiatorList",param,true,(data) => {
        this.isLoadinging = false;

        if (data.status == 200) {
          data = data.data;
          this.opData(data);

          this.mans.push(...data);
          this.pageNo++;
          this.pageMax = data.length < 20;
          if(data.length < 20) this.mans.push({});
          this.opModel();
        } else {
          modal.toast(data.msg);
        }
      });
    },
    
    /**********************************************输入框回调*/
    //确定键
    onReturn() {
      this.searchClick();
    },

    /********************************** 点击触发*/
    //搜索
    searchClick() {
      this.$refs.input && this.$refs.input.blur();
      this.searchKey = this.text;
      this.httpMans();
    },

    //人点击
    manClick(item) {

      var param = {'userId':item.userId};
      navigator.open('', "follw/UFollwManInfo",param);
    },
  },
};
</script>


<style src="@/_css/style.css"></style>
<style scoped>
/***********************************搜索*/
.search {
  flex-direction: row;
  align-items: center;
  width: 750px;
  height: 104px;
  padding-left: 40px;
  padding-right: 40px;
}
.search-content {
  flex-direction: row;
  align-items: center;
  width: 670px;
  height: 60px;
  border-radius: 4px;
}
.search-image {
  width: 24px;
  height: 24px;
  margin-left: 20px;
  margin-right: 20px;
}
.search-input{
  flex: 1;
  height: 88px;
  placeholder-color:#6E7488;
}
.search-but {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  height: 104px;
  padding-left: 20px;
  padding-right: 20px;
}
/********************************************************************* 列表*/
.list {
  margin-top: 20px;
  width: 750px;
}
.cell {
  flex-direction: column;
  align-items: center;
  width: 750px;
  margin-top: 20px;
}
.cell-info {
  flex-direction: row;
  align-items: center;
  width: 710px;
  padding: 50px;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}
.cell-image {
  width: 80px;
  height: 80px;
  border-radius: 40px ;

  margin-right: 40px;
}
.cell-exch {
  flex-direction: row;
  align-items: center;
  height: 33px;
  border-radius: 20px;
  border-width: 2px;
  padding-left: 15px;
  padding-right: 15px;
  margin-right: 12px;
}
.cell-mark{
  width: 300px;
  lines:1;
  text-overflow: ellipsis;
}
.cell-total {
  flex-direction: row;
  align-items: center;
  width: 710px;
  height: 64px;
  padding-left: 48px;
  padding-right: 48px;

  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}

/*********************** 刷新*/
.refresh {
  width: 750;
  flex-direction: row;
  justify-content: center;
}
.load {
  margin-top: 16px;
  height: 40px;
  width: 40px;
}

/*********************** 提示*/
.tipe {
  margin-left: 60px;
  margin-right: 60px;
  margin-top: 40px;
  margin-bottom: 140px;
}
.tipe-text {
  line-height: 30px;
}

/*********************** 宽高*/
.height20{
  height: 20px;
}
</style>